#include "point.h"
#include <math.h>

Point::Point()
{
    _x = 0; _y = 0; _z = 0;
}

Point::Point(const Point& pt)
{
    _x = pt._x;  _y = pt._y;  _z = pt._z;
}

Point::Point(double x, double y, double z)
{
    _x = x; _y = y; _z = z;
}

Point &Point::operator =(const Point &pt)
{
    _x = pt._x;    _y = pt._y;    _z = pt._z;
}

Point Point::operator +(const Point &pt) const
{
    return Point(_x + pt._x, _y + pt._y, _z + pt._z);
}

Point Point::operator -(const Point &pt) const
{
    return Point(_x - pt._x, _y - pt._y, _z - pt._z);
}

double Point::dot(const Point &pt)
{
    return _x * pt._x + _y * pt._y + _z * pt._z;
}

Point Point::cross(const Point &pt)
{
    Point v;
    v.x() = (_y * pt._z - _z * pt._y);
    v.y() = (_z * pt._x - _x * pt._z);
    v.z() = (_x * pt._y - _y * pt._x);

    return v;
}

void Point::normalize()
{
    double norm = sqrt(pow(_x, 2) + pow(_y, 2) + pow(_z, 2));

    _x /= norm; _y /= norm; _z /= norm;
}

void Point::draw()
{
}

double Point::distance(Point &pt) const
{
    return sqrt(pow(pt.x() - _x, 2) + pow(pt.y() - _y, 2) + pow(pt.z() - _z, 2));
}
